<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__ . '/../vendor/autoload.php';
if (PHP_VERSION_ID < 70000) {
    include_once __DIR__ . '/../var/bootstrap.php.cache';
}

$request = Request::createFromGlobals();
$response = Response::create('ok');

$hash = $request->get('hash');

if (!in_array($hash, ['davon@Jiang'])) {
    $response->setContent('error');
} else {
//    $command = "cd D:\mowhere\huobi\source\webSocket\src\HuobiWS && php ws_run.php stop";
    $command = "cd /data/wwwroot/huobi_WebSocket/src/HuobiWS && php ws_run.php stop ";
// 异步启用后台处理进程
    if ($resource = popen($command, 'r')) {
        while (!feof($resource)) {
            $buffer = fgets($resource, 4096);
//            echo $buffer;
//            printf("%s\r\n", $buffer);
        }
        pclose($resource);
    } else {
        $response->setContent($command);
        $response->send();
        exit();
    }

//    $command = "cd D:\mowhere\huobi\source\webSocket\src\HuobiWS && php ws_run.php start";
    $command = "cd /data/wwwroot/huobi_WebSocket/src/HuobiWS && php ws_run.php start";
// 异步启用后台处理进程
    if ($resource = popen($command, 'r')) {
        while (!feof($resource)) {
            $buffer = fgets($resource, 4096);
//            echo $buffer;
//            printf("%s\r\n", $buffer);
        }
        pclose($resource);
    }
}

$response->send();

unset($request, $response);